package com.ruoyi.common.redis.factory;

import com.ruoyi.common.redis.enums.LockType;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;

/**
 * 工厂类，根据类型创建锁
 *
 * @author Fei.Cong
 * @date 2024-06-04 17:10
 */
public final class LockFactory {

    public static RLock createLock(RedissonClient redissonClient, LockType lockType, String key) {
        switch (lockType) {
            case ReadLock:
                return redissonClient.getReadWriteLock(key).readLock();
            case WriteLock:
                return redissonClient.getReadWriteLock(key).writeLock();
            default:
                return redissonClient.getLock(key);
        }
    }
}
